<template>
  <div class="page">
    <div class="title">
      <router-link to="/product/list">
        <div class="left">
          <span class="iconfont icon-lf"></span>
          <span>返回</span>
        </div>
      </router-link>
      <span>商品详情</span>
      <span class="none">返回>aa</span>
    </div>
    <div class="img">
      <img src="@/assets/img/1-banner.png" alt />
    </div>
    <div class="desc">
      <div class="top">
        <span class="blue">直降</span>
        <span class="red">包邮</span>
        【山东】金秋红蜜桃 基地果园现摘现发 鲜甜红润肉厚 富含维生素
        <p>果园生态种植 皮薄香甜爽口 富含天然维C</p>
      </div>
      <div class="price">
        <span>
          <span class="first">￥</span>
          <span class="second">44.9</span>
          <span class="third">￥56.9</span>
        </span>
        <span class="fourth">3932人购买</span>
      </div>
    </div>
    <div class="list">
      <div class="top">
        <div class="left">
          <span>规格：X</span>
          2
        </div>
        <i class="iconfont icon-right_arrow"></i>
      </div>
      <div class="mid">
        <div class="left">
          <span>配送至：</span>
          <span class="address">距离你十万八千里的地方</span>
        </div>
        <i class="iconfont icon-right_arrow"></i>
      </div>
      <div class="bottom">
        <i class="iconfont icon-weixinzhifu"></i>
        <span>包邮</span>
      </div>
    </div>
    <div class="line"></div>
    <div class="footer">
      <div class="img-title">—— 商品详情 ——</div>
      <div class="images">
        <img src="@/assets/img/1-2.jpg" alt />
        <img src="@/assets/img/1-3.jpg" alt />
        <img src="@/assets/img/1-4.jpg" alt />
        <img src="@/assets/img/1-5.jpg" alt />
        <img src="@/assets/img/1-6.jpg" alt />
        <img src="@/assets/img/1-7.jpg" alt />
        <img src="@/assets/img/1-8.jpg" alt />
        <img src="@/assets/img/1-9.jpg" alt />
        <img src="@/assets/img/1-10.jpg" alt />
        <img src="@/assets/img/1-11.jpg" alt />
        <img src="@/assets/img/1-12.jpg" alt />
        <img src="@/assets/img/1-13.jpg" alt />
        <img src="@/assets/img/1-14.jpg" alt />
        <img src="@/assets/img/1-15.jpg" alt />
        <img src="@/assets/img/1-16.jpg" alt />
        <img src="@/assets/img/1-17.jpg" alt />
      </div>
      <div class="img-title">—— 预定流程及须知 ——</div>
      <img src="@/assets/img/1-18.png" alt />
      <div class="context">
        <p class="context-title">一、关于发货</p>
        <p class="context-con">
          个工作日内发出（周末、法定节假日需顺延）个工作日内发出（周末、法定节假日需顺延）；
        </p>
        <p class="context-title">一、关于发货</p>
        <p class="context-con">
          个工作日内发出（周末、法定节假日需顺延）个工作日内发出（周末、法定节假日需顺延）；
        </p>
        <p class="context-title">一、关于发货</p>
        <p class="context-con">
          个工作日内发出（周末、法定节假日需顺延）个工作日内发出（周末、法定节假日需顺延）；
        </p>
        <p class="context-title">一、关于发货</p>
        <p class="context-con">
          个工作日内发出（周末、法定节假日需顺延）个工作日内发出（周末、法定节假日需顺延）；
        </p>
      </div>
    </div>
    <div class="goods-icon">
      <div class="server">
        <div class="iconfont icon-liaotian"></div>
        客服
      </div>
      <div class="server">
        <div class="iconfont icon-icon-test"></div>
        收藏
      </div>
      <router-link to="/cart">
        <div class="server rel">
          <i class="iconfont icon-3"></i>
          购物车
          <span class="abs num" v-if="cartNum > 0">{{ cartNum }}</span>
        </div>
      </router-link>
      <div class="grow-1"></div>
      <div class="btn">
        <button @click="addCart" class="cart">加入购物车</button>
        <button class="buy">立即购买</button>
      </div>
    </div>
  </div>
</template>

<script>
import $axios from '@/utils/request'
export default {
  data() {
    return {
      productId: this.$route.params.productId,
      cartNum: 0,
    }
  },

  created() {},

  methods: {
    async addCart() {
      // 判断是否登录
      if (!this.$store.state.isLogin) {
        // 提示后跳转到登录页面
        this.$router.push('/my/login')
        return false
      }

      //1.发请求到后
      try {
        let data = { productId: this.productId }
        let res = await $axios.get('/cart/add', data)
        this.cartNum++
        this.$toast.success('添加成功')
      } catch (error) {
        this.$toast.fail(error)
      }
    },
  },
}
</script>

<style lang="less" scoped>
@import './detail.less';
.num {
  background: red;
  color: #fff;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  top: 0;
  right: 0;
}
</style>
